package com.xoa.dev.pz.service;


import com.xoa.dao.auth.AuthMapper;
import com.xoa.dev.pz.dao.MenuJdtMapper;
import com.xoa.dev.pz.model.MenuJdt;
import com.xoa.service.file.FileSortResetAuth;
import com.xoa.util.common.wrapper.BaseWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Service
public class MenuJdtService {
    @Autowired
    AuthMapper authMapper;
    @Resource
    private MenuJdtMapper menuJdtMapper;

    public BaseWrapper addMenuJdt(HttpServletRequest request, MenuJdt menuJdt, Map<String,Object> mmp){
        FileSortResetAuth resetAuth =new FileSortResetAuth();
        Map<String,String> param=resetAuth.reset("userId", (Map<String, String>)mmp.get("userId"))
                .reset("newUser",(Map<String, String>)mmp.get("newUser"))
                .reset("manageUser",(Map<String, String>)mmp.get("manageUser"))
                .reset("downUser",(Map<String, String>)mmp.get("downUser"))
                .reset("xunjian",(Map<String,String>)mmp.get("xunjian"))
                .getParam();
        menuJdt.setJdtMenuId(1);
        if(!String.valueOf(param.get("userId")).equals("null")){
            menuJdt.setJdtMenuUser(String.valueOf(param.get("userId")));//人口
        }
        if(!String.valueOf(param.get("downUser")).equals("null")){
            menuJdt.setJdtMenuIdCampus(String.valueOf(param.get("downUser")));//校园
        }
        if(!String.valueOf(param.get("manageUser")).equals("null")){
            menuJdt.setJdtMenuSpecialuser(String.valueOf(param.get("manageUser")));//特殊人群
        }
        if(!String.valueOf(param.get("newUser")).equals("null")){
            menuJdt.setJdtMenuHoust(String.valueOf(param.get("newUser")));//出租房
        }
        if(!String.valueOf(param.get("xunjian")).equals("null")){
            menuJdt.setJdtMenuMarck(String.valueOf(param.get("xunjian")));//巡检
        }




        List<MenuJdt> menuJdts= menuJdtMapper.menuJdtList();
        int total=0;
        if(menuJdts!=null&&menuJdts.size()>0){
            total =  menuJdtMapper.updateByPrimaryKeySelective(menuJdt);
        }else {
            total =  menuJdtMapper.insertSelective(menuJdt);
        }
        BaseWrapper baseWrapper=new BaseWrapper();
        if(total>0){
            baseWrapper.setFlag(true);
            baseWrapper.setStatus(true);
            baseWrapper.setMsg("操作成功！");
        }else{
            baseWrapper.setFlag(false);
            baseWrapper.setStatus(true);
            baseWrapper.setMsg("操作失败！");
        }
        return baseWrapper;
    }









}
